package class_0915SkipList;

public class SkipListTest {

    public static void main(String[] args) {
        SkipList<String> skipList = new SkipList<>();

        // 测试插入操作
        System.out.println("Inserting elements:");
        skipList.insert(1, "One");
        skipList.insert(2, "Two");
        skipList.insert(3, "Three");
        // 测试搜索操作

        System.out.println("Searching for elements:");
        printNode(skipList.search(1)); // 应输出 One
        printNode(skipList.search(2)); // 应输出 Two
        printNode(skipList.search(3)); // 应输出 Three
        printNode(skipList.search(4)); // 应输出 null (not found)

        // 测试删除操作
        System.out.println("Deleting element with key 2:");
        skipList.delete(2);

        // 再次测试搜索操作
        System.out.println("Searching for elements after deletion:");
        printNode(skipList.search(1)); // 应输出 One
        printNode(skipList.search(2)); // 应输出 null (not found)
        printNode(skipList.search(3)); // 应输出 Three
    }

    private static void printNode(SkipList.Node<String> node) {
        if (node != null) {
            System.out.println("Key: " + node.key + ", Value: " + node.value);
        } else {
            System.out.println("Node not found.");
        }
    }
}
